package com.example.payment.controller;

import com.example.common.result.R;
import com.example.payment.entity.Payment;
import com.example.payment.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;

@RestController
@RequestMapping("/api/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @GetMapping("/{id}")
    public R<Payment> getPayment(@PathVariable Long id) {
        return R.ok(paymentService.getById(id));
    }

    @GetMapping("/order/{orderNo}")
    public R<Payment> getPaymentByOrderNo(@PathVariable String orderNo) {
        return R.ok(paymentService.getPaymentByOrderNo(orderNo));
    }

    @PostMapping("/pay")
    public R<Payment> pay(@RequestParam String orderNo, @RequestParam Long userId, @RequestParam BigDecimal amount) {
        return R.ok(paymentService.pay(orderNo, userId, amount));
    }

    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return R.ok(paymentService.removeById(id));
    }
}
